package com.spider.silence.main;

import com.spider.silence.downloader.BaiduForumDownloader;
import com.spider.silence.downloader.MaLaDownLoader;
import com.spider.silence.env.job.BaiduForumInitJob;
import com.spider.silence.job.BaiduForumJob;
import com.spider.silence.pool.BaiduForumDownLoaderPool;
import com.spider.silence.pool.MaLaDownLoaderPool;
import com.spider.silence.utils.CommonUtils;
import com.spider.silence.utils.PropertiesUtil;
import com.spider.silence.utils.QuartzManager;

import com.spider.silence.worker.BaiduForumWorker;
import com.spider.silence.worker.MaLaWorker;
import com.spider.silence.worker.MalaModuleWorker;
import org.apache.log4j.PropertyConfigurator;

import java.util.ArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by zh on 2017/1/13.
 */
public class  BaiduForumMain {
    public static void main(String[] args) throws Exception{
        PropertyConfigurator.configure( PropertiesUtil.getLogPro());//初始化日志环境
        BaiduForumDownLoaderPool downLoaderPool = null;
        BaiduForumDownloader downLoader = null;
            //获取下载器池单例
             downLoaderPool=BaiduForumDownLoaderPool.getInstance();
            //从下载器池中获取下载器
            downLoader=(BaiduForumDownloader)downLoaderPool.fetchDownLoader(1000);
            //创建任务和把任务放到任务管理中心
            downLoader.initForums().generateTask();
            //初始化任务完后把下载器放回下载器中
            downLoaderPool.releaseDownLoader(downLoader);
            //创建线程池
            ExecutorService pool =  Executors.newFixedThreadPool(3000);

            //创建多个工作者线程从下载器单例池中取下载器处理从任务中心取得的任务 用完后把下载器放回到下载器池中
            for(int i=0;i<Integer.valueOf(PropertiesUtil.getVal("BaiduForum.WorkerCount"));i++){
                pool.execute(new BaiduForumWorker());
            }

    }
}
